#!/usr/bin/python3
# 文件名：client.py

# 导入 socket、sys 模块
import socket
import sys
import time
# 创建 socket 对象
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 

# 获取本地主机名
host = socket.gethostname() 

# 设置端口号
port = 9999

# 连接服务，指定主机和端口
s.connect((host, port))

# 接收小于 1024 字节的数据
x=1
while x==1:
    print(time.asctime(time.localtime(time.time())))
    print("          ")
    data = input("客户端说:")
    s.send(data.encode('utf-8'))
    buf = s.recv(1024)
    if len(buf):
        print(time.asctime(time.localtime(time.time())))
        print("          ")
        print ("服务端说:" + str(buf,"utf-8"))
    
